<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/common/html/head :: head_Normal(~{::title},~{::link},~{::style})">
    <title th:text=${title}></title>
    <link rel="stylesheet" th:href="@{/static/admin/assets/js/button/ladda/ladda.min.css}">
    <style type="text/css">
        .select-list ul li{
            list-style-type: none;
            float: left;
        }
    </style>

</head>

<body id="listbody">
<!-- 右边内容 -->
<div class="wrap-fluid">
<!--
    <div class="container-fluid paper-wrap bevel tlbr"  style="height:1280px">
-->
    <div class="container-fluid bevel tlbr"
         style="min-height: 600px;position: relative;overflow: hidden;">

        <!-- 内容 -->
     <!--   <div class="content-wrap" style="height: 1000px">-->
            <!-- 结束内容 -->
           <!-- <div class="row" style="height: 1000px">
                <div class="col-sm-12" style="height: 1000px">-->
                    <!-- 搜索条件 -->
<!--
                    <div class="nest" id="inlineClose" style="position: relative">
-->
                      <!--  <div class="title-alt">
                            <h6>搜索条件</h6>
                        </div>-->

                        <div class="body-nest" id="search_div"  style="display: block">
                            <div class="form_left">
                                <form role="form" class="form-inline">
                                    <div class="form-group" style="width: 16%">
                                        <label class="control-label timeBut2" style="float: left;padding-top: 10px">所属APP：</label>
                                     <!--  <select name="appName"  class="form-control" style="width: 66%" id="jnApp">
                                        </select>  -->
                                        <select name="appName"  class="form-control" style="width: 90px" id="jnApp">
                                        </select>
                                    </div>
                                   <!-- <button onclick="add()" class="btn btn-success" type="button"  style="margin-left: 63%"><i class="fa fa-plus"></i>&nbsp;新建</button>
                                    <button onclick="edit()" class="btn btn-success" type="button" style="margin-left: 1%"><i class="fa fa-edit"></i>&nbsp;编辑</button>
                                    <button onclick="del()" class="btn btn-success" type="button" style="margin-left: 1%"><i class="fa fa-remove"></i>&nbsp;删除</button>-->
                                    <button onclick="save()" class="btn btn-success" type="button" style="margin-left: 75%"><i class="fa fa-edit"></i>&nbsp;保存</button>
                                </form>
                            </div>
                        </div>
                  <!--  </div>-->
                    <!-- END搜索条件 -->
                    <!-- 空白页开始-->
                    <div class="nest" id="Blank_PageClose" style="height: 1000px;">
                        <div class="title-alt" style="height: 1px">
                        </div>

                        <div class="body-nest" id="Blank_Page_Content" style="height: 1000px;">
                                <iframe  width="100%"  height="90%"  id="jn" name="jn"  src="/rule/viewDetail" frameborder="0" marginheight="0" marginwidth="0" border="false"></iframe>
                        </div>
                    </div>
               <!-- </div>-->
                <!-- 空白页结束 -->
           <!-- </div>-->
            <!-- 结束内容 -->
       <!-- </div>-->
    </div>
</div>
<!-- 结束右边内容 -->

<!-- 通用js -->
<div th:include="admin/common/html/js :: onload_js">

</div>
<script th:src="@{/static/admin/assets/js/bootstrap/js/base_list.js}" type="text/javascript"></script>
<script th:src="@{/static/admin/assets/js/layer/layer.js}" type="text/javascript"></script>

<script th:inline="javascript">
    let rules = [[${rules}]];
    let initApp = 1;
    if(rules != null){
         initApp = rules.app;
    }

</script>

<script type="text/javascript">

    $.ajax({
        cache : true,
        type : "POST",
        url : "/user/info",
        headers: {
            "Authorization":getCookie("token")
        },
        async : false,
        error : function(request) {
            $.modal.alertError("系统错误");
        },
        success : function(data) {
            console.log(data)
            let apps = data.appNames;
            for (var i = 0; i < apps.length; i++) {
                if(apps[i] == initApp){
                    $("#jnApp").append("<option selected = 'selected'>" + apps[i] + "</option>");
                }else{
                    $("#jnApp").append("<option>" + apps[i] + "</option>");
                }
            }
        }
    });

    $("#jnApp").change(function () {
        let app = this.options[this.selectedIndex].value;
        let childWindow = $("#jn")[0].contentWindow;
        childWindow.getRules(app);
    });

    function add(){
        let app = $("#jnApp").val();
        let rules =  window.frames["jn"].document.getElementById("myWord").value;
        $.ajax({
            cache : true,
            type : "POST",
            url : "/rule/add",
            headers: {
                "Authorization":getCookie("token")
            },
            data:{"app":app,"rules":rules},
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
                console.log(data)
                layer.alert(data.msg)
            }
        });
    }
    function save(){
        let app = $("#jnApp").val();
        let rules =  window.frames["jn"].document.getElementById("myWord").value;
        $.ajax({
            cache : true,
            type : "POST",
            url : "/rule/save",
            headers: {
                "Authorization":getCookie("token")
            },
            data:{"app":app,"rules":rules},
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
                console.log(data)
                layer.alert(data.msg)
                $("#recordSearch", parent.document.body).trigger("click");
                parent.layer.closeAll()
            }
        });
    }
    function del(){
        let app = $("#jnApp").val();
        $.ajax({
            cache : true,
            type : "POST",
            url : "/rule/remove",
            headers: {
                "Authorization":getCookie("token")
            },
            data:{"app":app},
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
                console.log(data)
                layer.alert(data.msg)
                let childWindow = $("#jn")[0].contentWindow;
                childWindow.getRules(app);
            }
        });
    }
</script>

</body>

</html>
